//
//  CZVisitorViewController.swift
//  微博
//
//  Created by 霸气的刘吉庆 on 16/4/16.
//  Copyright © 2016年 ios. All rights reserved.
//

import UIKit

class CZVisitorViewController: UITableViewController,CZVisitorViewDelegate {
    
    
    //进行判断判断用户是否登录
    //登录就显示平常的界面,没有登录就显示没有登录的界面
    
    //定义一个属性,判断用户是否登录
    
    var userLogon: Bool = CZUserAccountViewModel.sharedViewModel.isLogin
    
    
    
    
    override func loadView() {
        
//        if userLogon {
//            super.loadView()
//            
//        }else{
//            
//            //没有登录,设置没有登录的界面
//            
//            setupVisitorView()
//            
//            
//        }
        
        
        //简单的设置,直接使用三木运算符
        
        userLogon ? super.loadView() : setupVisitorView()
        
        
        print(userLogon)
        
        
    }
    
    func setupVisitorView(){
        
        
        
        //设置setupView
        
        view = i
        
        //注意这个返回的是navigationBar
        
        
        
        //设置他左右两侧的按钮
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "didClickRegisterButton")
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "didClickLoginButton")
        
        
        
        
        
       
        
        
        
        
        
        
        
        
        
        
        
        
    }
    
    
    func didClickLoginButton() {
        
        
        //点击了左侧的注册按钮,效果是什么呢,
        
        //登录按钮被点击 首先,moda出来一个导航控制器
        
        
        presentViewController(UINavigationController(rootViewController:CZAuthorViewController()), animated: true, completion: nil)
        
        
        
        
        
        
        print("登录按钮被点击了")
        
        
    }
    
    func didClickRegisterButton() {
        
        
        print("注册按钮被点击了")
        
        
    }
    
    
    lazy var i:CZVisitorView = {
        
        
       let d = CZVisitorView()
        
        //设置他的代理
        
        d.delegate = self
        
       return d
        
    }()
    
    
    //懒加载空间
    
    
    
    
    
    

    override func viewDidLoad() {
        super.viewDidLoad()

        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false

        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // MARK: - Table view data source

    

    

   


}
